function formatTime(date) {
  var year = date.getFullYear()
  var month = date.getMonth() + 1
  var day = date.getDate()
  var hour = date.getHours()
  var minute = date.getMinutes()
  var second = date.getSeconds()

  return [year, month, day].map(formatNumber).join('-'); 
  // + ' ' + [hour, minute, second].map(formatNumber).join(':')
}

function formatNumber(n) {
  n = n.toString()
  return n[1] ? n : '0' + n
}

function json2Form(json) {
    var str = [];
    for(var p in json){
        str.push(encodeURIComponent(p) + "=" + encodeURIComponent(json[p]));
    }
    return str.join("&");
}
function getTagStr(tag) {
    var str=tag;
    if (tag =='refundable'){
      str='支持退款'
    }
    if (tag =='onlyHoliday'){
      str='节假日开放'
    }
     if (tag =='onlyWeekend'){
      str='周末开放'
    }
    return str;
}
function getTotalPrice(count,price){
var totalprice=(parseFloat(price)*count).toFixed(2).toString();
  console.log(parseFloat(price),count,totalprice)
  return totalprice;
}

function getOrderStatus(code){
  let str = '';
  switch (code){
    case 'audit_refund_fail' :
    str = '退单审核失败'
    break;
    case 'audit_refund_success':
      str = '退单审核成功'
    break;
    case 'cancel_pay':
      str = '交易撤销'
    break;
    case 'payed':
      str = '已支付'
    break;
    case 'paying':
      str = '支付中'
    break;
    case 'refunded':
      str = '已退款'
    break;
    case 'settlemented':
      str = '已结算'
    break;
    case 'time_out_close_pay':
      str = '订单超时,交易关闭'
    break;
    case 'wait_audit_refund':
      str = '退单待审核'
    break;
    case 'wait_pay':
      str = '待支付'
    break;
    case 'wait_refund':
      str = '待退款'
    break;
    case 'wait_settlement':
      str = '等待结果'
    break;
    default:
    break
  }

  return str;
}
module.exports = {
  formatTime: formatTime,
  json2Form:json2Form,
  getTagStr:getTagStr,
  getTotalPrice:getTotalPrice,
  getOrderStatus:getOrderStatus
}

